from flask_sqlalchemy import SQLAlchemy

db = SQLAlchemy()

MoePoint = db.Table('moepoint',
                    db.Column('vtuber_id', db.Integer, db.ForeignKey('vtuber.id')),
                    db.Column('moe_id', db.Integer, db.ForeignKey('moe.id'))
                    )


class Vtuber(db.Model):
    """Vtuber的信息表"""

    __tablename__ = 'vtuber'

    class GENDER:
        GIRL = '1'
        BOY = '2'

    id = db.Column('id', db.Integer, primary_key=True, doc='VID')
    name = db.Column('name', db.String, nullable=False, doc='中文名')
    jpname = db.Column('jpname', db.String, nullable=False, doc='英文名')
    age = db.Column('age', db.Integer, default=0, doc='年龄')
    height = db.Column('height', db.Numeric, doc='身高')
    haircolor = db.Column('haircolor', db.String, doc='发色')
    eyecolor = db.Column('eyecolor', db.String, doc='瞳色')
    birthday = db.Column('birthday', db.Date, doc='生日')
    constellation = db.Column('constellation', db.String, nullable=False, doc='星座')
    gender = db.Column('gender', db.String, default='1', doc='性别')
    introduction = db.Column('introduction', db.String, nullable=False, doc='简介')

    # 外键关联
    moes = db.relationship('Moe', secondary=MoePoint, backref='vtubers', lazy='dynamic')
    nicknames = db.relationship('Nickname', backref='vtuber', lazy='dynamic')
    comments = db.relationship('Comment', backref='vtuber', lazy='dynamic')


class Moe(db.Model):
    """萌点属性表"""

    __tablename__ = 'moe'

    id = db.Column('id', db.Integer, primary_key=True, doc='主键')
    moename = db.Column(db.String, nullable=False, doc='moe属性名')


class Nickname(db.Model):
    """Vtuber昵称表"""

    __tablename__ = 'nickname'

    id = db.Column('id', db.Integer, primary_key=True, doc='主键')
    vtuber_id = db.Column(db.Integer, db.ForeignKey("vtuber.id"), nullable=False, doc='vtuber_id')
    nickname = db.Column(db.String, nullable=False, doc='moe属性名')


class Comment(db.Model):
    """Vtuber评论(吐槽)表"""

    __tablename__ = 'comment'

    id = db.Column('id', db.Integer, primary_key=True, doc='主键')
    vtuber_id = db.Column(db.Integer, db.ForeignKey("vtuber.id"), nullable=False, doc='vtuber_id')
    content = db.Column(db.String, nullable=False, doc='吐槽的内容')
